package demo;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PersonTest {
    public static void main(String[] args) {
//        SerializableAction("person.out","person.out");
        File file=new File("./a/b/c/d/e/f/g/h/j/k/l");
        file.mkdirs();
//        deleteDire("./a");
    }

    /**
     * 文件序列化和反序列化
     * @param outPath 生成文件的路径
     * @param inPath 读取已经序列化的文件路径
     */
    public static void SerializableAction(String outPath,String inPath){
        try (ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(outPath));
             ObjectInputStream ois=new ObjectInputStream(new FileInputStream(inPath))){
            /*序列化
             * 对象->文件*/
            Person person=new Person("李梅梅","上饶","教师","123123123123123123123123",22);
            oos.writeObject(person);
            oos.flush();
            /*反序列化
             * 文件->对象*/
            Person person1= (Person) ois.readObject();
            System.out.println(person1.toString());
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    /**
     * 删除文件夹
     * */
    public static void deleteDire(String dirPath){
        File dir = new File(dirPath);
        if (dir.exists()&&dir.isDirectory()) {
            File []items=dir.listFiles();
            for (File item:items
                 ) {
                if (item.listFiles().length==0) {
                    item.delete();
                }
                deleteDire(item.getPath());
            }
            dir.delete();
        }
    }
}
